﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using YAF.Core;
using YAF.Types.Interfaces;
using YAF.Types.EventProxies;

public partial class Logout : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //Session["logged"] = null;
        //Session["name"] = null;
        //Session["lastlogin"] = null;
        //Session["type"] = null;
        //Session["cid"] = null;
        long userid;
        if (Request.Cookies["texchange"] != null)
        {
            HttpCookie c = new HttpCookie("texchange");
            if (Request.Cookies["texchange"]["cid"] != null)
            {
                long.TryParse(DAO.GlobalSettings.Decrypt(Request.Cookies["texchange"]["cid"].ToString()), out userid);
                DAO.UserManagement.setUserLogged(userid, false);
            }
            c.Expires = DateTime.Now.AddDays(-1d);
            Response.Cookies.Add(c);
        }
        if (Request.Cookies["texchange"] != null)
        {
            Request.Cookies["texchange"].Expires = DateTime.Now.AddDays(-1);
            Response.Cookies["texchange"].Expires = DateTime.Now.AddDays(-1);
        }
        try
        {
            ForumPage currentPage = new ForumPageRegistered();
            YafContext PageContext = currentPage.PageContext;
            FormsAuthentication.SignOut();
            currentPage.Get<IRaiseEvent>().Raise(new UserLogoutEvent(PageContext.PageUserID));
            //currentPage.Session.Abandon();
        }
        catch { }
        Response.Redirect("~/Default.aspx");
    }
}
